const _DB = require('../../../utils/db.js');

Page({

  data: {
    sysList:['软件系','网络系','计算机系','数码系','电子系','国贸系','财会系','游戏系','管理系','外语系'],
    sysName:'------选择您的所在系------',
  },

  onLoad: function (options) {

  },

  //所在系
  selectSys:function(e){
    var index = e.detail.value;
    var _this = this;
    this.setData({sysName:_this.data.sysList[index]});
  },

  //注册表单提交
  bindSave:function(e){
    var teacherID = e.detail.value.teacherID;
    var name = e.detail.value.name;
    var sex = e.detail.value.sex; 
    var password = e.detail.value.password;
    var sys = this.data.sysList[e.detail.value.sys];
    var phone = e.detail.value.phone;
    var phonemat = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;

    var info = {}
    
    if(teacherID==''||teacherID.length!=4||name==''||sex==''||password==''||sys==null||phone==''||!phonemat.test(phone)){
      wx.showToast({
        title: '请填入正确信息',
        icon:'none'
      })
    }else{
      info.teacherID = teacherID;
      info.name = name;
      info.sex = sex;
      info.password = password;
      info.phone = phone;
      info.address = sys;

      wx.showToast({
        title: '正在注册',
        icon:'loading',
        mask:true,
      })

      _DB.teacherReg(info,function(res){
        if (res == '该用户已经注册过了'){
          wx.showToast({
            title: '该用户已经注册过了',
            icon: 'none',
          })
        }else if(res == '注册成功'){
          wx.showModal({
            title: '提示',
            content: '注册成功，是否跳转登录页面',
            success: function (res) {
              if (res.confirm) {
                wx.navigateBack({})
              }
            }
          })
        }
      })
    }
  }
})